// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HKMarketPanel.java

package com.boci.clientapp.orderstatus.ui.control;

import com.boci.clientapp.main.*;
import com.boci.clientapp.orderstatus.OrderStatusScrPanel;
import com.boci.clientapp.orderstatus.action.OrderStatusAction;
import com.boci.clientapp.orderstatus.constant.OrderStatusConst;
import com.boci.clientapp.orderstatus.vo.OrderStatusDetailVO;
import com.boci.clientapp.orderstatus.vo.OrderStatusVO;
import com.boci.common.ui.control.*;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;

// Referenced classes of package com.boci.clientapp.orderstatus.ui.control:
//            GoRenderer, GoEditor

public class HKMarketPanel extends JPanel
    implements TableModelListener, ActionListener
{

    public HKMarketPanel(Locale pLocale)
    {
        msgConf = ClientAppLoader.getMessagesConfigurator();
        initGUI(pLocale);
        setText(pLocale);
        setVisibleLblBtn(true);
    }

    private void initGUI(Locale pLocale)
    {
        headerPanel = new JPanel();
        hkMarketSclPane = new JScrollPane();
        tblHKMarket = new JTable();
        tmHKMarket = new CMTableModel();
        goRenderer = new GoRenderer(pLocale);
        goEditor = new GoEditor(pLocale);
        nameRenderer = new NameRenderer(pLocale);
        ccyRenderer = new NameRenderer(pLocale);
        stringRenderer = new StringRenderer();
        numericRenderer = new StringRenderer();
        codeRenderer = new StringRenderer();
        ccyRenderer.setHorizontalAlignment(0);
        numericRenderer.setHorizontalAlignment(4);
        codeRenderer.setHorizontalAlignment(0);
        tblHKMarket.setModel(tmHKMarket);
        applyTableSorter(tblHKMarket, tmHKMarket);
        tblHKMarket.setSelectionMode(1);
        tblHKMarket.setCellSelectionEnabled(false);
        tmHKMarket.addTableModelListener(this);
        tmHKMarket.setEditableCol(7);
        hkMarketSclPane.setViewportView(tblHKMarket);
        hkMarketSclPane.getViewport().setOpaque(false);
        hkMarketSclPane.setOpaque(false);
        hkMarketSclPane.setBorder(new EtchedBorder(1));
        setTableHeight();
        lblHKMarketTitle = new JLabel();
        lblLastUpdatedTimeText = new JLabel();
        lblLastUpdatedTimeValue = new JLabel();
        btnRefresh = new JButton();
        btnRefresh.setActionCommand("REFRESH");
        btnRefresh.addActionListener(this);
        headerPanel.setBackground(Color.WHITE);
        headerPanel.setLayout(new BoxLayout(headerPanel, 0));
        headerPanel.setPreferredSize(new Dimension(0, 25));
        leftPanel = new JPanel();
        leftPanel.setLayout(new FlowLayout(0));
        leftPanel.add(lblHKMarketTitle);
        leftPanel.setOpaque(false);
        rightPanel = new JPanel();
        rightPanel.setLayout(new FlowLayout(2));
        rightPanel.setOpaque(false);
        rightPanel.add(lblLastUpdatedTimeText);
        headerPanel.add(leftPanel);
        headerPanel.add(rightPanel);
        headerPanel.add(btnRefresh);
        setLayout(new BorderLayout());
        setOpaque(false);
        add(headerPanel, "North");
        add(hkMarketSclPane, "Center");
    }

    private void setFont(Locale pLocale)
    {
        lblHKMarketTitle.setFont(ClientAppLoader.getSmallBoldTextFont(pLocale));
        lblLastUpdatedTimeText.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        lblLastUpdatedTimeValue.setFont(ClientAppLoader.getSmallBoldTextFont(pLocale));
        tblHKMarket.getTableHeader().setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        stringRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        codeRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        numericRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        btnRefresh.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
    }

    public void setText(Locale pLocale)
    {
        currLocale = pLocale;
        tmHKMarket.removeTableModelListener(this);
        goRenderer.setText(pLocale);
        goEditor.setText(pLocale);
        nameRenderer.setText(pLocale);
        ccyRenderer.setText(pLocale);
        lblHKMarketTitle.setText(msgConf.getUIMessages("ORDER_STATUS.HKMARKET", pLocale));
        updateLastUpdateTime();
        btnRefresh.setText(msgConf.getUIMessages("ORDER_STATUS.REFRESH", pLocale));
        setFont(pLocale);
        String strHKMarketColName[] = {
            msgConf.getUIMessages("ORDER_STATUS.COL_DATE_TIME", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_TRANS_TYPE", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_QTY", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_NAME", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_CODE", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_PRICE", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_STATUS", pLocale), msgConf.getUIMessages("ORDER_STATUS.COL_GO", pLocale), ""
        };
        tmHKMarket.setColumnName(strHKMarketColName);
        tmHKMarket.fireTableStructureChanged();
        for(int i = 0; i < tblHKMarket.getColumnCount(); i++)
        {
            TableColumn column = tblHKMarket.getColumnModel().getColumn(i);
            if(i == 3)
                column.setCellRenderer(nameRenderer);
            else
            if(i == 2 || i == 5)
                column.setCellRenderer(numericRenderer);
            else
            if(i == 1 || i == 4)
                column.setCellRenderer(codeRenderer);
            else
            if(i == 7)
            {
                column.setMinWidth(OrderStatusConst.COL_WIDTH_ORDER_STATUS_HKMARKET[i]);
                column.setMaxWidth(OrderStatusConst.COL_WIDTH_ORDER_STATUS_HKMARKET[i]);
                column.setCellRenderer(goRenderer);
                column.setCellEditor(goEditor);
            } else
            if(i == 8)
            {
                column.setMinWidth(OrderStatusConst.COL_WIDTH_ORDER_STATUS_HKMARKET[i]);
                column.setMaxWidth(OrderStatusConst.COL_WIDTH_ORDER_STATUS_HKMARKET[i]);
            } else
            {
                column.setCellRenderer(stringRenderer);
            }
            column.setPreferredWidth(OrderStatusConst.COL_WIDTH_ORDER_STATUS_HKMARKET[i]);
        }

        tmHKMarket.addTableModelListener(this);
        if(responseVO != null)
            refresh(responseVO);
    }

    public void refresh(ResponseVO pResponseVO)
    {
        String strTmpDate = "";
        tmHKMarket.removeTableModelListener(this);
        if(pResponseVO == null)
        {
            responseVO = pResponseVO;
            Object strTableData[][] = new Object[0][9];
            tmHKMarket.setData(strTableData);
            tmHKMarket.fireTableDataChanged();
            hkMarketSclPane.getViewport().setViewPosition(new Point(0, 0));
            setTableHeight();
        } else
        if(pResponseVO instanceof OrderStatusVO)
        {
            responseVO = pResponseVO;
            OrderStatusVO orderStatusVO = (OrderStatusVO)pResponseVO;
            orderStatusDetailVOList = orderStatusVO.getHkStockList();
            Object strTableData[][] = new Object[orderStatusDetailVOList.size()][9];
            for(int i = 0; i < orderStatusDetailVOList.size(); i++)
            {
                OrderStatusDetailVO orderStatusDetailVO = (OrderStatusDetailVO)orderStatusDetailVOList.get(i);
                String strName[] = {
                    orderStatusDetailVO.getName(), orderStatusDetailVO.getName_chi(), orderStatusDetailVO.getName_chs()
                };
                strTmpDate = StringUtil.formatTableDateTime(orderStatusDetailVO.getPlacementDate());
                strTableData[i][0] = strTmpDate != null ? ((Object) (strTmpDate)) : "";
                strTableData[i][1] = msgConf.getUIMessages(orderStatusDetailVO.getBuyOrSell(), currLocale);
                String strQty = StringUtil.formatQtyValue(orderStatusDetailVO.getOrderQuantity());
                String strPrice = StringUtil.formatPriceValue(orderStatusDetailVO.getPrice());
                strTableData[i][2] = strQty;
                strTableData[i][3] = strName;
                strTableData[i][4] = orderStatusDetailVO.getSymbol();
                String strNoPriceTypes[] = ClientAppLoader.getNoPriceOrdTypes();
                boolean isNoPriceType = false;
                int j = 0;
                do
                {
                    if(j >= strNoPriceTypes.length)
                        break;
                    if(strNoPriceTypes[j].equals(orderStatusDetailVO.getOrderType()))
                    {
                        isNoPriceType = true;
                        break;
                    }
                    j++;
                } while(true);
                if(isNoPriceType)
                    strTableData[i][5] = "";
                else
                    strTableData[i][5] = strPrice;
                String strOrderStatusKey = (new StringBuilder()).append("ORDER_STATUS.").append(orderStatusDetailVO.getOrderStatus()).toString();
                String strOrderStatusValue = msgConf.getUIMessages(strOrderStatusKey, currLocale);
                if(strOrderStatusValue.equals(strOrderStatusKey))
                    strTableData[i][6] = orderStatusDetailVO.getOrderStatus();
                else
                    strTableData[i][6] = strOrderStatusValue;
                strTableData[i][7] = "";
                strTableData[i][8] = orderStatusDetailVO;
            }

            tmHKMarket.setData(strTableData);
            tmHKMarket.fireTableDataChanged();
            hkMarketSclPane.getViewport().setViewPosition(new Point(0, 0));
            setTableHeight();
        }
        tmHKMarket.addTableModelListener(this);
    }

    public void tableChanged(TableModelEvent e)
    {
        PerformanceLogger.startAppTimer();
        int intSelectedCol = e.getColumn();
        int intSelectedRow = e.getFirstRow();
        String strActionType = (String)tmHKMarket.getValueAt(intSelectedRow, intSelectedCol);
        if(strActionType == null || strActionType.length() == 0)
            return;
        if(strActionType.equals("CHANGE_EDIT") || strActionType.equals("CANCEL_REVIEW") || strActionType.equals("DETAIL"))
        {
            OrderStatusDetailVO orderStatusDetailVO = null;
            Object obj = tmHKMarket.getValueAt(intSelectedRow, 8);
            if(obj instanceof OrderStatusDetailVO)
                orderStatusDetailVO = (OrderStatusDetailVO)obj;
            else
                return;
            OrderStatusAction orderStatusAction = new OrderStatusAction();
            orderStatusAction.doProcess(getInputValue(orderStatusDetailVO), strActionType);
            goEditor.resetValue();
        }
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append("ORDER_STATUS_SCREEN.").append(strActionType).toString());
    }

    private void applyTableSorter(JTable pTable, CMTableModel pTableModel)
    {
        int sortedCols[] = OrderStatusConst.sortedCols;
        if(sortedCols == null)
            return;
        CMTableSorter tableSorter = new CMTableSorter(pTableModel);
        pTable.getTableHeader().setReorderingAllowed(false);
        for(int i = 0; i < sortedCols.length; i++)
            tableSorter.addAllowSortColumn(sortedCols[i]);

        pTable.setModel(tableSorter);
        tableSorter.setTableHeader(pTable.getTableHeader());
    }

    private HashMap getInputValue(ResponseVO pResponseVO)
    {
        HashMap map = new HashMap();
        map.put("SELECTED_VO", pResponseVO);
        return map;
    }

    public void setVisibleLblBtn(boolean pFlag)
    {
        lblLastUpdatedTimeText.setVisible(pFlag);
        btnRefresh.setVisible(pFlag);
    }

    public void updateLastUpdateTime()
    {
        String strBlank = "   ";
        String strResult = "";
        ApplicationService appServ = ApplicationService.getInstance();
        if(appServ != null)
        {
            OrderStatusScrPanel orderStatusScrPanel = (OrderStatusScrPanel)appServ.getMainPanel().getPanel("ORDER_STATUS_MODULE", "ORDER_STATUS_SCREEN");
            if(orderStatusScrPanel != null)
                strResult = (new StringBuilder()).append(msgConf.getUIMessages("ORDER_STATUS.LAST_UPDATED_TIME", currLocale)).append("  ").append(orderStatusScrPanel.getOrderStatusLastUpdateDateTimeStr()).append(strBlank).toString();
        }
        lblLastUpdatedTimeText.setText(strResult);
    }

    public void actionPerformed(ActionEvent e)
    {
        PerformanceLogger.startAppTimer();
        String strActionType = e.getActionCommand();
        OrderStatusAction orderStatusAction = new OrderStatusAction();
        orderStatusAction.doProcess(getInputValue(strActionType), strActionType);
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append("ORDER_STATUS_SCREEN.").append(strActionType).toString());
    }

    public HashMap getInputValue(String pActionType)
    {
        HashMap inpMap = new HashMap();
        return inpMap;
    }

    public void setTableHeight()
    {
        int intTableHeight = tblHKMarket.getRowHeight() * 3 + tblHKMarket.getTableHeader().getPreferredSize().height + 4;
        hkMarketSclPane.setPreferredSize(new Dimension(0, intTableHeight));
        hkMarketSclPane.setMinimumSize(new Dimension(0, intTableHeight));
    }

    private JPanel headerPanel;
    private JPanel leftPanel;
    private JPanel rightPanel;
    private JTable tblHKMarket;
    private CMTableModel tmHKMarket;
    private JScrollPane hkMarketSclPane;
    private JLabel lblHKMarketTitle;
    private JLabel lblLastUpdatedTimeText;
    private JLabel lblLastUpdatedTimeValue;
    private JButton btnRefresh;
    private GoRenderer goRenderer;
    private GoEditor goEditor;
    private NameRenderer nameRenderer;
    private NameRenderer ccyRenderer;
    private StringRenderer stringRenderer;
    private StringRenderer numericRenderer;
    private StringRenderer codeRenderer;
    private ArrayList orderStatusDetailVOList;
    private MessagesConfigurator msgConf;
    private ResponseVO responseVO;
    private Locale currLocale;
}
